package com.ruoyi.house_sale.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.house_sale.domain.CustState;
import com.ruoyi.house_sale.service.ICustStateService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 客户类型Controller
 * 
 * @author ruoyi
 * @date 2022-04-09
 */
@RestController
@RequestMapping("/house_sale/CustState")
public class CustStateController extends BaseController
{
    @Autowired
    private ICustStateService custStateService;

    /**
     * 查询客户类型列表
     */
    @PreAuthorize("@ss.hasPermi('house_sale:CustState:list')")
    @GetMapping("/list")
    public TableDataInfo list(CustState custState)
    {
        startPage();
        List<CustState> list = custStateService.selectCustStateList(custState);
        return getDataTable(list);
    }

    /**
     * 导出客户类型列表
     */
    @PreAuthorize("@ss.hasPermi('house_sale:CustState:export')")
    @Log(title = "客户类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CustState custState)
    {
        List<CustState> list = custStateService.selectCustStateList(custState);
        ExcelUtil<CustState> util = new ExcelUtil<CustState>(CustState.class);
        util.exportExcel(response, list, "客户类型数据");
    }

    /**
     * 获取客户类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('house_sale:CustState:query')")
    @GetMapping(value = "/{custstateid}")
    public AjaxResult getInfo(@PathVariable("custstateid") Long custstateid)
    {
        return AjaxResult.success(custStateService.selectCustStateByCuststateid(custstateid));
    }

    /**
     * 新增客户类型
     */
    @PreAuthorize("@ss.hasPermi('house_sale:CustState:add')")
    @Log(title = "客户类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CustState custState)
    {
        return toAjax(custStateService.insertCustState(custState));
    }

    /**
     * 修改客户类型
     */
    @PreAuthorize("@ss.hasPermi('house_sale:CustState:edit')")
    @Log(title = "客户类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CustState custState)
    {
        return toAjax(custStateService.updateCustState(custState));
    }

    /**
     * 删除客户类型
     */
    @PreAuthorize("@ss.hasPermi('house_sale:CustState:remove')")
    @Log(title = "客户类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{custstateids}")
    public AjaxResult remove(@PathVariable Long[] custstateids)
    {
        return toAjax(custStateService.deleteCustStateByCuststateids(custstateids));
    }
}
